package com.wz.wzliving.commodity.controller;

import com.wz.wzliving.commodity.entity.CategoryEntity;
import com.wz.wzliving.commodity.service.CategoryService;
import com.wzcommon.utils.PageUtils;
import com.wzcommon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 商品分类表
 *
 * @author wangzeng
 * @email 3107187288@qq.com
 * @date 2025-03-25 20:13:56
 */
@RestController
@RequestMapping("commodity/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = categoryService.queryPage(params);

        return R.ok().put("page", page);
    }

    /*
    返回结构
    /
     */
    @RequestMapping("/list/tree")

    public R listTree(@RequestParam Map<String, Object> params){
        List<CategoryEntity> categoryEntities = categoryService.listTree();

        return R.ok().put("data", categoryEntities);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")

    public R info(@PathVariable("id") Long id){
		CategoryEntity category = categoryService.getById(id);

        return R.ok().put("category", category);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody CategoryEntity category){
		categoryService.save(category);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody CategoryEntity category){
		categoryService.updateById(category);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] ids){
		categoryService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
